#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
char buf[(1<<21)+5],*p1,*p2;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
int read(){
	int f=0,x=0;
	char ch=getchar();
	while(!isdigit(ch)){f|=(ch=='-');ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return f?-x:x;
}
int n,root=1;
int l[2005],r[2005],f[2005];
int ls[2005],rs[2005],fa[2005];
int ans[2005];
void zig(int x){
	if(fa[x]==root)root=x;
	if(x==ls[fa[x]]){
		fa[rs[x]]=fa[x];
		ls[fa[x]]=rs[x];
		rs[x]=fa[x]; 
		int p=fa[fa[x]];
		if(ls[p]==fa[x])ls[p]=x;
		else rs[p]=x;
		fa[fa[x]]=x;
		fa[x]=p;
	}else{
		fa[ls[x]]=fa[x];
		rs[fa[x]]=ls[x];
		ls[x]=fa[x];
		int p=fa[fa[x]];
		if(ls[p]==fa[x])ls[p]=x;
		else rs[p]=x;
		fa[fa[x]]=x;
		fa[x]=p;
	}
}
void dfs(int x,int dep){
	ans[x]=(ans[x]+dep)%mod;
	if(ls[x]!=0)dfs(ls[x],dep+1);
	if(rs[x]!=0)dfs(rs[x],dep+1);
}
void splay(int x){
	while(x!=root){
		if(fa[x]==root){
			zig(x);
		}else if((x==ls[fa[x]]&&fa[x]==ls[fa[fa[x]]])||(x==rs[fa[x]]&&fa[x]==rs[fa[fa[x]]])){
			zig(fa[x]);
			zig(x);
		}else{
			zig(x);
			zig(x);
		}
	}
	dfs(x,0);
}
int main(){
	freopen("dream.in","r",stdin);
	freopen("dream.out","w",stdout);
	n=read();
	for(int i=1;i<=n;i++){
		l[i]=read(),r[i]=read();
		f[l[i]]=f[r[i]]=i;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++)ls[j]=l[j],rs[j]=r[j],fa[j]=f[j];
		root=1;
		splay(i);
	}
	for(int i=1;i<=n;i++){
		cout<<ans[i]<<endl;
	}
	return 0;
} 
